﻿Imports SIAVU.Dominio

Namespace Presentacion

    Partial Public Class VerHistorial
        Inherits System.Web.UI.Page

        Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
            If Not (Page.IsPostBack) Then
                MostrarPanelBusquedaSegunUsuario()

            End If

            If (cmbAnio.SelectedItem Is Nothing) Then
                cmbAnio.SelectedIndex = cmbAnio.Items.IndexOfValue(Date.Now.Date.Year.ToString)
                cmbMes.SelectedIndex = cmbMes.Items.IndexOfValue(Date.Now.Date.Month.ToString)
            End If
            SetearControles()
        End Sub

#Region "Atributos privados"

        Private _PanelHistorialVisible As Boolean

#End Region

#Region "Propiedades"

        Public Property PanelHistorialVisible() As Boolean
            Get
                Return _PanelHistorialVisible
            End Get
            Set(ByVal value As Boolean)
                pnlHistorial.Visible = value
            End Set
        End Property

#End Region
        
#Region "Métodos"
        Private Sub MostrarPanelBusquedaSegunUsuario()
            Try
                Dim oUsuario As New Usuario
                oUsuario.getByID(Session("UsuarioID"))
                If oUsuario.TipoUsuario = ETipoUsuario.Programador Then
                    pnlHistorial.Visible = _PanelHistorialVisible
                Else
                    ucBusqueda1.Visible = False
                    btnVolver.Visible = False
                    pnlHistorial.Visible = True
                    Session("UsuarioIDucMiProgramacion") = Session("UsuarioID")
                End If
            Catch ex As Exception

            End Try

        End Sub

        Public Sub SetearControles()
            ucHistorial.NombreParaMostrar = ""
            ucHistorial.PeriodoProgramacion = cmbAnio.SelectedItem.Value.ToString() + "/" + cmbMes.SelectedItem.Value.ToString()
            ucHistorial.TipoMiProgramacion = ETipoProgramacion.PreProgramacion
            ucHistorial.LimpiarSession()
            ucHistorial.InicializarScheduler()
        End Sub

#End Region

#Region "Eventos"

        Protected Sub btnVolver_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnVolver.Click
            pnlHistorial.Visible = False
            ucBusqueda1.Visible = True
        End Sub

        Protected Sub cmbAnio_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cmbAnio.SelectedIndexChanged
            Session("cmbAnio") = cmbAnio.SelectedItem.Value
            SetearControles()
        End Sub

        Protected Sub cmbMes_SelectedIndexChanged(ByVal sender As Object, ByVal e As EventArgs) Handles cmbMes.SelectedIndexChanged
            Session("cmbMes") = cmbMes.SelectedItem.Value
            SetearControles()

        End Sub

#End Region

    End Class

End Namespace
